package org.javaforever.cookieshop.controller;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.javaforever.cookieshop.domain.CustOrderBean;
import org.javaforever.cookieshop.domain.GoodsBean;
import org.javaforever.cookieshop.domain.OrderItemBean;
import org.javaforever.cookieshop.service.CustOrderService;
import org.javaforever.cookieshop.service.GoodsService;
import org.javaforever.cookieshop.service.OrderItemService;
import org.javaforever.cookieshop.utils.BooleanUtil;
import org.javaforever.cookieshop.utils.PDFUtil;
import org.javaforever.cookieshop.utils.POIExcelUtil;
import org.javaforever.cookieshop.utils.POIPPTUtil;
import org.javaforever.cookieshop.utils.StringUtil;
import org.javaforever.cookieshop.utils.WordUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping(value = "/orderItemController")
@RestController
public class OrderItemController {
	public OrderItemBean tempOrderItem = new OrderItemBean();
	@Autowired
	protected CustOrderService custOrderService;
	@Autowired
	protected GoodsService goodsService;
	@Autowired
	protected OrderItemService service;

	@RequestMapping(value = "/activateAllOrderItems", method = RequestMethod.POST)
	public Map<String,Object> activateAllOrderItems(@RequestParam(value = "ids", required = true) String ids) throws Exception{
        Map<String,Object> result = new TreeMap<String,Object>();
        service.activateAllOrderItems(ids);
        result.put("success",true);
        result.put("data",null);
        return result;
	}
	@RequestMapping(value = "/activateOrderItem", method = RequestMethod.POST)
	public Map<String,Object> activateOrderItem(@RequestParam Long id) throws Exception{
        Map<String,Object> result = new TreeMap<String,Object>();
        service.activateOrderItem(id);
        result.put("success",true);
        result.put("data",null);
        return result;
	}
	@RequestMapping(value = "/addOrderItem", method = RequestMethod.POST)
	public Map<String,Object> addOrderItem(@RequestBody OrderItemBean orderItem) throws Exception{
        Map<String,Object> result = new TreeMap<String,Object>();
        service.addOrderItem(orderItem);
        result.put("success",true);
        result.put("data",null);
        return result;
	}
	@RequestMapping(value = "/checkAccessOrderItem", method = RequestMethod.GET)
	public Map<String,Object> checkAccessOrderItem() throws Exception{
        Map<String,Object> result = new TreeMap<String,Object>();
        result.put("success",true);
        result.put("data",null);
        return result;
	}
	@RequestMapping(value = "/cloneAllOrderItems", method = RequestMethod.POST)
	public Map<String,Object> cloneAllOrderItems(@RequestParam(value = "ids", required = true) String ids) throws Exception{
        Map<String,Object> result = new TreeMap<String,Object>();
        service.cloneAllOrderItems(ids);
        result.put("success",true);
        result.put("data",null);
        return result;
	}
	@RequestMapping(value = "/cloneOrderItem", method = RequestMethod.POST)
	public Map<String,Object> cloneOrderItem(@RequestParam Long id) throws Exception{
        Map<String,Object> result = new TreeMap<String,Object>();
        service.cloneOrderItem(id);
        result.put("success",true);
        result.put("data",null);
        return result;
	}
	@RequestMapping(value = "/deleteAllOrderItems", method = RequestMethod.POST)
	public Map<String,Object> deleteAllOrderItems(@RequestParam(value = "ids", required = true) String ids) throws Exception{
        Map<String,Object> result = new TreeMap<String,Object>();
        service.deleteAllOrderItems(ids);
        result.put("success",true);
        result.put("data",null);
        return result;
	}
	@RequestMapping(value = "/deleteOrderItem", method = RequestMethod.POST)
	public Map<String,Object> deleteOrderItem(@RequestParam Long id) throws Exception{
        Map<String,Object> result = new TreeMap<String,Object>();
        service.deleteOrderItem(id);
        result.put("success",true);
        result.put("data",null);
        return result;
	}
	@RequestMapping(value = "/exportOrderItems")
	public void exportOrderItems(HttpSession session,HttpServletResponse response,HttpServletRequest request) throws Exception{
        try(OutputStream out = response.getOutputStream()){
            response.addHeader("Content-Disposition", "attachment;filename=OrderItems.xls");
            List<OrderItemBean> list = service.listAllOrderItems();
            List<List<Object>> contents = new ArrayList<>();
            String sheetName = "订单项信息表";
            String [] headers = {"序号","名字","活跃","价格","商品数","货品","订单"};
            Boolean [] isImages = {false,false,false,false,false,false,false};
            
            for (OrderItemBean orderItem:list) {
                Long goods = orderItem.getGoods();
                GoodsBean goodsType0;
                String goodsName0 = "";
                if (goods != null) {
                    goodsType0 = goodsService.findGoodsById(goods);
                    if (goodsType0 !=null) goodsName0 = goodsType0.getName();
                }
                Long custOrder = orderItem.getCustOrder();
                CustOrderBean custOrderType0;
                String custOrderName0 = "";
                if (custOrder != null) {
                    custOrderType0 = custOrderService.findCustOrderById(custOrder);
                    if (custOrderType0 !=null) custOrderName0 = custOrderType0.getName();
                }
                Object [] row = {StringUtil.toNullString(orderItem.getId()),orderItem.getName(),StringUtil.toNullString(orderItem.getActive()),StringUtil.toNullString(orderItem.getPrice()),StringUtil.toNullString(orderItem.getAmount()),goodsName0,custOrderName0};
                contents.add(Arrays.asList(row));
            }
            
            POIExcelUtil.exportExcelWorkbookWithImage(out, sheetName, Arrays.asList(headers), contents, Arrays.asList(isImages));
        }
	}
	@RequestMapping(value = "/exportOrderItemsPDF")
	public void exportOrderItemsPDF(HttpSession session,HttpServletResponse response,HttpServletRequest request) throws Exception{
        try(OutputStream out = response.getOutputStream()){
            response.addHeader("Content-Disposition", "attachment;filename=OrderItems.pdf");
            List<OrderItemBean> list = service.listAllOrderItems();
            List<List<Object>> contents = new ArrayList<>();
            String sheetName = "订单项信息表";
            String [] headers = {"序号","名字","活跃","价格","商品数","货品","订单"};
            Boolean [] isImages = {false,false,false,false,false,false,false};
            
            for (OrderItemBean orderItem:list) {
                Long goods = orderItem.getGoods();
                GoodsBean goodsType0;
                String goodsName0 = "";
                if (goods != null) {
                    goodsType0 = goodsService.findGoodsById(goods);
                    if (goodsType0 !=null) goodsName0 = goodsType0.getName();
                }
                Long custOrder = orderItem.getCustOrder();
                CustOrderBean custOrderType0;
                String custOrderName0 = "";
                if (custOrder != null) {
                    custOrderType0 = custOrderService.findCustOrderById(custOrder);
                    if (custOrderType0 !=null) custOrderName0 = custOrderType0.getName();
                }
                Object [] row = {StringUtil.toNullString(orderItem.getId()),orderItem.getName(),StringUtil.toNullString(orderItem.getActive()),StringUtil.toNullString(orderItem.getPrice()),StringUtil.toNullString(orderItem.getAmount()),goodsName0,custOrderName0};
                contents.add(Arrays.asList(row));
            }
            
            PDFUtil.exportPDFWithImage(out, sheetName, Arrays.asList(headers), contents, Arrays.asList(isImages));
        }
	}
	@RequestMapping(value = "/exportOrderItemsWord")
	public void exportOrderItemsWord(HttpSession session,HttpServletResponse response,HttpServletRequest request) throws Exception{
        try(OutputStream out = response.getOutputStream()){
            response.addHeader("Content-Disposition", "attachment;filename=OrderItems.doc");
            List<OrderItemBean> list = service.listAllOrderItems();
            List<List<Object>> contents = new ArrayList<>();
            String sheetName = "订单项信息表";
            String [] headers = {"序号","名字","活跃","价格","商品数","货品","订单"};
            Boolean [] isImages = {false,false,false,false,false,false,false};
            
            for (OrderItemBean orderItem:list) {
                Long goods = orderItem.getGoods();
                GoodsBean goodsType0;
                String goodsName0 = "";
                if (goods != null) {
                    goodsType0 = goodsService.findGoodsById(goods);
                    if (goodsType0 !=null) goodsName0 = goodsType0.getName();
                }
                Long custOrder = orderItem.getCustOrder();
                CustOrderBean custOrderType0;
                String custOrderName0 = "";
                if (custOrder != null) {
                    custOrderType0 = custOrderService.findCustOrderById(custOrder);
                    if (custOrderType0 !=null) custOrderName0 = custOrderType0.getName();
                }
                Object [] row = {StringUtil.toNullString(orderItem.getId()),orderItem.getName(),StringUtil.toNullString(orderItem.getActive()),StringUtil.toNullString(orderItem.getPrice()),StringUtil.toNullString(orderItem.getAmount()),goodsName0,custOrderName0};
                contents.add(Arrays.asList(row));
            }
            
            WordUtil.exportWordWithImage(out, sheetName, Arrays.asList(headers), contents, Arrays.asList(isImages));
        }
	}
	@RequestMapping(value = "/exportPPTOrderItems")
	public void exportPPTOrderItems(HttpSession session,HttpServletResponse response,HttpServletRequest request) throws Exception{
        try(OutputStream out = response.getOutputStream()){
            response.addHeader("Content-Disposition", "attachment;filename=OrderItems.pptx");
            List<OrderItemBean> list = service.listAllOrderItems();
            List<List<Object>> contents = new ArrayList<>();
            String sheetName = "订单项信息表";
            String [] headers = {"序号","名字","活跃","价格","商品数","货品","订单"};
            Boolean [] isImages = {false,false,false,false,false,false,false};
            
            for (OrderItemBean orderItem:list) {
                Long goods = orderItem.getGoods();
                GoodsBean goodsType0;
                String goodsName0 = "";
                if (goods != null) {
                    goodsType0 = goodsService.findGoodsById(goods);
                    if (goodsType0 !=null) goodsName0 = goodsType0.getName();
                }
                Long custOrder = orderItem.getCustOrder();
                CustOrderBean custOrderType0;
                String custOrderName0 = "";
                if (custOrder != null) {
                    custOrderType0 = custOrderService.findCustOrderById(custOrder);
                    if (custOrderType0 !=null) custOrderName0 = custOrderType0.getName();
                }
                Object [] row = {StringUtil.toNullString(orderItem.getId()),orderItem.getName(),StringUtil.toNullString(orderItem.getActive()),StringUtil.toNullString(orderItem.getPrice()),StringUtil.toNullString(orderItem.getAmount()),goodsName0,custOrderName0};
                contents.add(Arrays.asList(row));
            }
            
            POIPPTUtil.exportPPTWithImage(out, sheetName, Arrays.asList(headers), contents, Arrays.asList(isImages));
        }
	}
	@RequestMapping(value = "/filterOrderItemsExcel", method = RequestMethod.GET)
	public void filterOrderItemsExcel(HttpSession session,
		HttpServletResponse response,
		HttpServletRequest request,
		@RequestParam(value = "name", required = false) String name,
		@RequestParam(value = "active", required = false) String active,
		@RequestParam(value = "price", required = false) Double price,
		@RequestParam(value = "amount", required = false) Integer amount,
		@RequestParam(value = "goods", required = false) Long goods,
		@RequestParam(value = "custOrder", required = false) Long custOrder) throws Exception{
        OrderItemBean orderItem0 = new OrderItemBean();
        if (!StringUtil.isBlank(name)) orderItem0.setName(name);
        Boolean activeBool = BooleanUtil.parseBoolean(active);
        if (activeBool != null) orderItem0.setActive(activeBool);
        if (price != null) orderItem0.setPrice(price);
        if (amount != null) orderItem0.setAmount(amount);
        if (goods != null) orderItem0.setGoods(goods);
        if (custOrder != null) orderItem0.setCustOrder(custOrder);
        try(OutputStream out = response.getOutputStream()){
            response.addHeader("Content-Disposition", "attachment;filename=OrderItems.xls");
            List<OrderItemBean> list = service.searchOrderItemsByFields(orderItem0);
            List<List<Object>> contents = new ArrayList<>();
            String sheetName = "订单项信息表";
            String [] headers = {"序号","名字","活跃","价格","商品数","货品","订单"};
            Boolean [] isImages = {false,false,false,false,false,false,false};
            
            for (OrderItemBean orderItem:list) {
                Long goods0 = orderItem.getGoods();
                GoodsBean goodsType0;
                String goodsName0 = "";
                if (goods0 != null) {
                    goodsType0 = goodsService.findGoodsById(goods0);
                    if (goodsType0 !=null) goodsName0 = goodsType0.getName();
                }
                Long custOrder0 = orderItem.getCustOrder();
                CustOrderBean custOrderType0;
                String custOrderName0 = "";
                if (custOrder0 != null) {
                    custOrderType0 = custOrderService.findCustOrderById(custOrder0);
                    if (custOrderType0 !=null) custOrderName0 = custOrderType0.getName();
                }
                Object [] row = {StringUtil.toNullString(orderItem.getId()),orderItem.getName(),StringUtil.toNullString(orderItem.getActive()),StringUtil.toNullString(orderItem.getPrice()),StringUtil.toNullString(orderItem.getAmount()),goodsName0,custOrderName0};
                contents.add(Arrays.asList(row));
            }
            
            POIExcelUtil.exportExcelWorkbookWithImage(out, sheetName, Arrays.asList(headers), contents, Arrays.asList(isImages));
        }
	}
	@RequestMapping(value = "/filterOrderItemsPDF", method = RequestMethod.GET)
	public void filterOrderItemsPDF(HttpSession session,
		HttpServletResponse response,
		HttpServletRequest request,
		@RequestParam(value = "name", required = false) String name,
		@RequestParam(value = "active", required = false) String active,
		@RequestParam(value = "price", required = false) Double price,
		@RequestParam(value = "amount", required = false) Integer amount,
		@RequestParam(value = "goods", required = false) Long goods,
		@RequestParam(value = "custOrder", required = false) Long custOrder) throws Exception{
        OrderItemBean orderItem0 = new OrderItemBean();
        if (!StringUtil.isBlank(name)) orderItem0.setName(name);
        Boolean activeBool = BooleanUtil.parseBoolean(active);
        if (activeBool != null) orderItem0.setActive(activeBool);
        if (price != null) orderItem0.setPrice(price);
        if (amount != null) orderItem0.setAmount(amount);
        if (goods != null) orderItem0.setGoods(goods);
        if (custOrder != null) orderItem0.setCustOrder(custOrder);
        try(OutputStream out = response.getOutputStream()){
            response.addHeader("Content-Disposition", "attachment;filename=OrderItems.pdf");
            List<OrderItemBean> list = service.searchOrderItemsByFields(orderItem0);
            List<List<Object>> contents = new ArrayList<>();
            String sheetName = "订单项信息表";
            String [] headers = {"序号","名字","活跃","价格","商品数","货品","订单"};
            Boolean [] isImages = {false,false,false,false,false,false,false};
            
            for (OrderItemBean orderItem:list) {
                Long goods0 = orderItem.getGoods();
                GoodsBean goodsType0;
                String goodsName0 = "";
                if (goods0 != null) {
                    goodsType0 = goodsService.findGoodsById(goods0);
                    if (goodsType0 !=null) goodsName0 = goodsType0.getName();
                }
                Long custOrder0 = orderItem.getCustOrder();
                CustOrderBean custOrderType0;
                String custOrderName0 = "";
                if (custOrder0 != null) {
                    custOrderType0 = custOrderService.findCustOrderById(custOrder0);
                    if (custOrderType0 !=null) custOrderName0 = custOrderType0.getName();
                }
                Object [] row = {StringUtil.toNullString(orderItem.getId()),orderItem.getName(),StringUtil.toNullString(orderItem.getActive()),StringUtil.toNullString(orderItem.getPrice()),StringUtil.toNullString(orderItem.getAmount()),goodsName0,custOrderName0};
                contents.add(Arrays.asList(row));
            }
            
            PDFUtil.exportPDFWithImage(out, sheetName, Arrays.asList(headers), contents, Arrays.asList(isImages));
        }
	}
	@RequestMapping(value = "/filterOrderItemsWord", method = RequestMethod.GET)
	public void filterOrderItemsWord(HttpSession session,
		HttpServletResponse response,
		HttpServletRequest request,
		@RequestParam(value = "name", required = false) String name,
		@RequestParam(value = "active", required = false) String active,
		@RequestParam(value = "price", required = false) Double price,
		@RequestParam(value = "amount", required = false) Integer amount,
		@RequestParam(value = "goods", required = false) Long goods,
		@RequestParam(value = "custOrder", required = false) Long custOrder) throws Exception{
        OrderItemBean orderItem0 = new OrderItemBean();
        if (!StringUtil.isBlank(name)) orderItem0.setName(name);
        Boolean activeBool = BooleanUtil.parseBoolean(active);
        if (activeBool != null) orderItem0.setActive(activeBool);
        if (price != null) orderItem0.setPrice(price);
        if (amount != null) orderItem0.setAmount(amount);
        if (goods != null) orderItem0.setGoods(goods);
        if (custOrder != null) orderItem0.setCustOrder(custOrder);
        try(OutputStream out = response.getOutputStream()){
            response.addHeader("Content-Disposition", "attachment;filename=OrderItems.doc");
            List<OrderItemBean> list = service.searchOrderItemsByFields(orderItem0);
            List<List<Object>> contents = new ArrayList<>();
            String sheetName = "订单项信息表";
            String [] headers = {"序号","名字","活跃","价格","商品数","货品","订单"};
            Boolean [] isImages = {false,false,false,false,false,false,false};
            
            for (OrderItemBean orderItem:list) {
                Long goods0 = orderItem.getGoods();
                GoodsBean goodsType0;
                String goodsName0 = "";
                if (goods0 != null) {
                    goodsType0 = goodsService.findGoodsById(goods0);
                    if (goodsType0 !=null) goodsName0 = goodsType0.getName();
                }
                Long custOrder0 = orderItem.getCustOrder();
                CustOrderBean custOrderType0;
                String custOrderName0 = "";
                if (custOrder0 != null) {
                    custOrderType0 = custOrderService.findCustOrderById(custOrder0);
                    if (custOrderType0 !=null) custOrderName0 = custOrderType0.getName();
                }
                Object [] row = {StringUtil.toNullString(orderItem.getId()),orderItem.getName(),StringUtil.toNullString(orderItem.getActive()),StringUtil.toNullString(orderItem.getPrice()),StringUtil.toNullString(orderItem.getAmount()),goodsName0,custOrderName0};
                contents.add(Arrays.asList(row));
            }
            
            WordUtil.exportWordWithImage(out, sheetName, Arrays.asList(headers), contents, Arrays.asList(isImages));
        }
	}
	@RequestMapping(value = "/filterPPTOrderItems", method = RequestMethod.GET)
	public void filterPPTOrderItems(HttpSession session,
		HttpServletResponse response,
		HttpServletRequest request,
		@RequestParam(value = "name", required = false) String name,
		@RequestParam(value = "active", required = false) String active,
		@RequestParam(value = "price", required = false) Double price,
		@RequestParam(value = "amount", required = false) Integer amount,
		@RequestParam(value = "goods", required = false) Long goods,
		@RequestParam(value = "custOrder", required = false) Long custOrder) throws Exception{
        OrderItemBean orderItem0 = new OrderItemBean();
        if (!StringUtil.isBlank(name)) orderItem0.setName(name);
        Boolean activeBool = BooleanUtil.parseBoolean(active);
        if (activeBool != null) orderItem0.setActive(activeBool);
        if (price != null) orderItem0.setPrice(price);
        if (amount != null) orderItem0.setAmount(amount);
        if (goods != null) orderItem0.setGoods(goods);
        if (custOrder != null) orderItem0.setCustOrder(custOrder);
        try(OutputStream out = response.getOutputStream()){
            response.addHeader("Content-Disposition", "attachment;filename=OrderItems.pptx");
            List<OrderItemBean> list = service.searchOrderItemsByFields(orderItem0);
            List<List<Object>> contents = new ArrayList<>();
            String sheetName = "订单项信息表";
            String [] headers = {"序号","名字","活跃","价格","商品数","货品","订单"};
            Boolean [] isImages = {false,false,false,false,false,false,false};
            
            for (OrderItemBean orderItem:list) {
                Long goods0 = orderItem.getGoods();
                GoodsBean goodsType0;
                String goodsName0 = "";
                if (goods0 != null) {
                    goodsType0 = goodsService.findGoodsById(goods0);
                    if (goodsType0 !=null) goodsName0 = goodsType0.getName();
                }
                Long custOrder0 = orderItem.getCustOrder();
                CustOrderBean custOrderType0;
                String custOrderName0 = "";
                if (custOrder0 != null) {
                    custOrderType0 = custOrderService.findCustOrderById(custOrder0);
                    if (custOrderType0 !=null) custOrderName0 = custOrderType0.getName();
                }
                Object [] row = {StringUtil.toNullString(orderItem.getId()),orderItem.getName(),StringUtil.toNullString(orderItem.getActive()),StringUtil.toNullString(orderItem.getPrice()),StringUtil.toNullString(orderItem.getAmount()),goodsName0,custOrderName0};
                contents.add(Arrays.asList(row));
            }
            
            POIPPTUtil.exportPPTWithImage(out, sheetName, Arrays.asList(headers), contents, Arrays.asList(isImages));
        }
	}
	@RequestMapping(value = "/findOrderItemById", method = RequestMethod.POST)
	public Map<String,Object> findOrderItemById(@RequestParam Long id) throws Exception{
        Map<String,Object> result = new TreeMap<String,Object>();
        OrderItemBean orderItem = service.findOrderItemById(id);
        result.put("success",true);
        result.put("data",orderItem);
        return result;
	}
	@RequestMapping(value = "/findOrderItemByName", method = RequestMethod.POST)
	public Map<String,Object> findOrderItemByName(@RequestParam(value = "name", required = true) String name) throws Exception{
        Map<String,Object> result = new TreeMap<String,Object>();
        OrderItemBean orderItem = service.findOrderItemByName(name);
        result.put("success",true);
        result.put("data",orderItem);
        return result;
	}
	@RequestMapping(value = "/listActiveOrderItems", method = RequestMethod.POST)
	public Map<String,Object> listActiveOrderItems() throws Exception{
        Map<String,Object> result = new TreeMap<String,Object>();
        List<OrderItemBean> list = service.listActiveOrderItems();
        result.put("success",true);
        result.put("rows",list);
        return result;
	}
	@RequestMapping(value = "/listAllOrderItems", method = RequestMethod.POST)
	public Map<String,Object> listAllOrderItems() throws Exception{
        Map<String,Object> result = new TreeMap<String,Object>();
        List<OrderItemBean> list = service.listAllOrderItems();
        result.put("success",true);
        result.put("rows",list);
        return result;
	}
	@RequestMapping(value = "/searchOrderItemsByFieldsByPage", method = RequestMethod.POST)
	public Map<String,Object> searchOrderItemsByFieldsByPage(@RequestParam(value = "page", required = false) Integer pagenum,
		@RequestParam(value = "rows", required = false) Integer pagesize,
		@RequestParam(value = "last", required = false) String lastFlag,
		@RequestParam(value = "name", required = false) String name,
		@RequestParam(value = "active", required = false) String active,
		@RequestParam(value = "price", required = false) Double price,
		@RequestParam(value = "amount", required = false) Integer amount,
		@RequestParam(value = "goods", required = false) Long goods,
		@RequestParam(value = "custOrder", required = false) Long custOrder) throws Exception{
        OrderItemBean orderItem = new OrderItemBean();
        if (!StringUtil.isBlank(name)) orderItem.setName(name);
        Boolean activeBool = BooleanUtil.parseBoolean(active);
        if (activeBool != null) orderItem.setActive(activeBool);
        if (price != null) orderItem.setPrice(price);
        if (amount != null) orderItem.setAmount(amount);
        if (goods != null) orderItem.setGoods(goods);
        if (custOrder != null) orderItem.setCustOrder(custOrder);
        if (pagesize==null || pagesize <= 0) pagesize = 10;
        Integer recordCount = service.countSearchOrderItemsByFieldsRecords(orderItem);
        Integer pageCount = (int)Math.ceil((double)recordCount/pagesize);
        if (pageCount <= 1) pageCount = 1;
        if (pagenum==null || pagenum <= 1) pagenum = 1;
        if (pagenum >= pageCount) pagenum = pageCount;
        Boolean lastFlagBool = BooleanUtil.parseBoolean(lastFlag);
        if (lastFlagBool == null) lastFlagBool = false;
        if (lastFlagBool) pagenum = pageCount;
        Map<String,Object> result = new TreeMap<String,Object>();
        List<OrderItemBean> orderItemList = service.searchOrderItemsByFieldsByPage(orderItem,pagesize,pagenum);
        result.put("success",true);
        result.put("rows",orderItemList);
        result.put("total",recordCount);
        result.put("page",pagenum);
        return result;
	}
	@RequestMapping(value = "/softDeleteAllOrderItems", method = RequestMethod.POST)
	public Map<String,Object> softDeleteAllOrderItems(@RequestParam(value = "ids", required = true) String ids) throws Exception{
        Map<String,Object> result = new TreeMap<String,Object>();
        service.softDeleteAllOrderItems(ids);
        result.put("success",true);
        result.put("data",null);
        return result;
	}
	@RequestMapping(value = "/softDeleteOrderItem", method = RequestMethod.POST)
	public Map<String,Object> softDeleteOrderItem(@RequestParam Long id) throws Exception{
        Map<String,Object> result = new TreeMap<String,Object>();
        service.softDeleteOrderItem(id);
        result.put("success",true);
        result.put("data",null);
        return result;
	}
	@RequestMapping(value = "/toggleOneOrderItem", method = RequestMethod.POST)
	public Map<String,Object> toggleOneOrderItem(@RequestParam Long id) throws Exception{
        Map<String,Object> result = new TreeMap<String,Object>();
        service.toggleOneOrderItem(id);
        result.put("success",true);
        result.put("data",null);
        return result;
	}
	@RequestMapping(value = "/toggleOrderItem", method = RequestMethod.POST)
	public Map<String,Object> toggleOrderItem(@RequestParam Long id) throws Exception{
        Map<String,Object> result = new TreeMap<String,Object>();
        service.toggleOrderItem(id);
        result.put("success",true);
        result.put("data",null);
        return result;
	}
	@RequestMapping(value = "/updateOrderItem", method = RequestMethod.POST)
	public Map<String,Object> updateOrderItem(@RequestBody OrderItemBean orderItem) throws Exception{
        Map<String,Object> result = new TreeMap<String,Object>();
        service.updateOrderItem(orderItem);
        result.put("success",true);
        result.put("data",null);
        return result;
	}
}

